<template>
	<view class="bg-white">
		<view class="userInfo" v-for="(item,i) in userList">
			<view @click="checkDetail(item,i)" class="between">
				<view class="left">
					<view class="between">
						<view class="start-center">
							<image v-if="item.campusImage" class="img-campus" :src="hostApi+item.campusImage"></image>
							<image v-else class="img-campus" src="/static/images/campus/campuslogo.png"></image>
							<text class="campus-name">{{item.campusName}}</text>
						</view>

					</view>
					<view class="hasCard">
						<view class="info">
							<text class="name">{{item.patName}}</text>
							<!-- <text>{{item.patSex == 1 ? '男' : '女'}}</text> -->
							<!-- <text>{{new Date().getFullYear() - item.certId.substring(6, 10)}}</text> -->
							<text class="check-card-default" v-if="item.loginStatus==1">默认</text>
							<text class="check-card" v-else @click.stop="selectUser(item,i)">设为默认</text>
						</view>
						<view class="pat-card">
							<text class="name">就诊卡：{{item.patId}}</text>
						</view>
					</view>
				</view>
				<view class="text-center">
					<view>电子就诊卡</view>
					<!-- <image class="img" src="../../static/images/icon/qrcode.png" mode="" @click="showCode = true">
					</image> -->
					<view class="mar-10">
						<tkiQrcodeVue ref="qrcode" onval :val="item.patId" :size="100" :load-make="true"
							:show-loading="false" />
					</view>
					<view class="qr-txt">就诊二维码</view>
				</view>

			</view>
		</view>

		<!-- 添加就诊卡 -->
		<view class="add-card" @click="toAddPatientCardPage">
			<view>
				<image class="card" src="/static/images/patient/addPatient.png"></image>
				<view class="font-weight">添加就诊卡</view>
				<view class="color-gray">您还可以添加 {{10-userList.length}} 张就诊卡</view>
			</view>
		</view>
		<view class="shouquan" @click="toShouQuan">
			<image class="left" src="/static/images/patient/shouquan.png"></image>
			<view class="mar-5">
				一键授权，已有健康卡用户直接绑定
			</view>
			<image class="right" src="/static/images/patient/changjiantou.png"></image>
		</view>
		<!-- 		<PopCard :show="show" :title="title" mode="top" @close="close">
			<slot name="content">
				<view>aaa</view>
			</slot>
		</PopCard> -->
		<u-popup :show="show" mode="top" @close="close" @open="open">
			<view>
				<text>人生若只如初见，何事秋风悲画扇</text>
			</view>
		</u-popup>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	// import PopCard from "@/components/PopCard/index.vue"
	import {
		mapGetters,
		mapActions
	} from 'vuex'
	import {
		selectCampus
	} from '../../api/campus';
	import tkiQrcodeVue from '../../components/QrCode/tki-qrcode.vue';
	export default {
		components: {
			// PopCard
			tkiQrcodeVue
		},
		computed: {
			...mapGetters(['userInfo', 'systemParams', 'userList', "hostApi"]),
		},
		data() {
			return {
				title: '登高望远',
				description: '欲穷千里目，更上一层楼',
				show: false,
				logo: ""
			}
		},
		mounted() {
			this.init();
		},
		methods: {
			...mapActions(['changeUser']),
			init() {
				console.log(this.userList)
			},
			checkDetail(val, i) {
				uni.setStorageSync("patientCardDetail", val)
				uni.navigateTo({
					url: '/pages/Login/patientCardDetail'
				})
			},
			selectUser(val, i) {
				if (this.userInfo.patId == val.patId) {
					console.log("不能对自己进行切换")
					return;
				}
				this.changeUser(val.patId).then(data => {
					this.$refs.uToast.show({
						title: val.patName + " 为默认就诊卡",
						type: 'success',
						icon: false,
					})
				}).catch(e => {})
			},
			toAddPatientCardPage() {
				if (this.userList.length >= 10) {
					return;
				}
				uni.navigateTo({
					url: '/pages/Login/addPatient'
				})
			},
			toShouQuan() {
				if (this.userList.length >= 10) {
					return;
				}
				uni.navigateTo({
					url: '/pages/Login/healthCardList'
				})
			},
			open() {
				this.show = true;
			},
			close() {
				this.show = false;
			}
		}
	}
</script>

<style scoped>
	.img-campus {
		width: 20px;
		height: 20px;
		border-radius: 16rpx;
		margin-right: 10rpx;
	}

	.campus-name {
		font-family: AlibabaPuHuiTi, AlibabaPuHuiTi;
		font-weight: 400;
		font-size: 14px;
		color: #999999;
		line-height: 20px;
		text-align: left;
		font-style: normal;
		text-transform: none;

	}


	.add-card {
		padding: 12rpx 20rpx;
		border-radius: 20rpx;
		height: 240rpx;
		font-size: 28rpx;
		margin: 16rpx;
		border: 1px dashed rgb(118, 165, 249);
		display: flex;
		justify-content: center;
		text-align: center;
		align-items: center;

		.card {
			width: 100rpx;
			height: 100rpx;
		}
	}

	.img {
		width: 40px;
		height: 40px;
		margin: 10px 0 0 0;
	}

	.userInfo {
		background: linear-gradient(to right, rgb(204, 246, 251), rgb(159, 232, 237));
		background-size: 100% 100%;
		border-radius: 6rpx;
		/* height: 240rpx; */
		color: black;
		font-size: 28rpx;
		margin: 16rpx;
		padding: 16px;

		.left {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
		}

		.hasCard {
			.info {
				font-family: AlibabaPuHuiTi, AlibabaPuHuiTi;
				font-weight: 400;
				font-size: 18px;
				color: #333333;
				line-height: 30px;
				text-align: left;
				font-style: normal;
				text-transform: none;

				.name {
					font-size: 20px;
					margin-right: 16upx;
				}

				text {
					margin-right: 16upx;
				}

				.ele-card {
					padding: 4upx 12upx;
					background-color: #FFF;
					border-radius: 40upx;
					color: $theme-color;
				}
			}

			.pat-card {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 16px;
				color: gray;
				line-height: 44px;


			}

			.qr {
				display: flex;
				flex-direction: column;
				align-items: center;



				.qr-txt {
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 16upx;
					color: black;
				}
			}

			.card-code,
			.card-change-user {
				font-size: 32rpx;
				display: flex;
				flex-direction: row;
				justify-content: flex-start;
				align-items: center;

				text:first-child {
					color: $text-color-active;
					margin-right: 10rpx;
				}
			}

		}

		.noCard {
			width: 100%;
			height: 100%;
			justify-content: center;
			align-items: center;
			color: #FFF;

			>.iconfont {
				font-size: 50rpx;
				// color: $text-color-active;
				margin-right: 10rpx;
			}
		}
	}

	.check-card-default {
		background-color: white;
		color: rgb(117, 165, 249);
		padding: 4upx 12upx;
		border-radius: 32upx;
		border: 1px solid #FBFFFF;
		margin-left: 16upx;
	}

	.check-card {
		padding: 4upx 12upx;
		border-radius: 32upx;
		border: 1px solid #FBFFFF;
		margin-left: 16upx;
	}

	.shouquan {
		color: rgb(80, 141, 247);
		text-align: center;
		display: flex;
		justify-content: center;
		align-items: center;
		font-weight: bold;

		.left {
			width: 30rpx;
			height: 30rpx;
		}

		.right {
			width: 50rpx;
			height: 50rpx;
		}
	}
</style>